<template>
  <div class="app-container calendar-list-container">
    <div v-if="!opShow">
      <search :list="queryList" :queryEntity="queryEntity"></search>
      <buttons :showQuery="true" :showBack="false" @query="doQuery" :list="btnList" :disabled="disabled" placeholder="客户名称" :permissions="permissions" @detail="doDetail"
        @log="doLog"></buttons>
      <grid :columns="columns" :multi="false" :url="queryUrl" ref="mainGrid" height="auto" diffHeight="105" @change="rowCilck" :queryEntity="queryEntity" :pagination="true"
        :permissions="permissions" @detail="doDetail" @log="doLog"></grid>
    </div>
  </div>
</template>

<script>
import request from '@/router/axios'
import url from '@/const/apiURL'
import grid from '@/components/Grid'
import buttons from '@/components/Buttons'
import { Message, MessageBox } from 'element-ui'
import { mapGetters } from 'vuex'
import { YesOrNoFormatter } from '@/const/dict'
import search from '@/components/Search'
import { colunms } from '@/const/colunms'
import { dict } from '@/const/dict'
import { queryField } from '@/const/query'


export default {
  components: { grid, buttons, search },
  data () {
    return {
      queryUrl: url.WMS_STOCK_LIST_URL,
      disabled: true,
      opShow: false,
      queryEntity: { key: 'key' },
      columns: [
        {
          label: '操作', width: 100, prop: 'op', align: 'center', template: 'op', opList: [
            { name: '详情', clickName: 'detail', auth: 'wms_stock_detail' },
            { name: '日志', clickName: 'log', auth: 'wms_stock_log' }
          ]
        },
        { label: '仓库名称', width: 120, prop: 'warehouseName', align: 'left' },
        { label: '物料名称', width: 360, prop: 'materialName', align: 'center' },
        { label: this.global.modelName, width: 100, prop: 'goodsName', align: 'center' },
        { label: this.global.modelProp, width: 100, prop: 'modelProp', align: 'center' },
        { label: '克重', width: 80, prop: 'weight', align: 'center' },
        { label: '单位', width: 80, prop: 'unit', align: 'center' },
        { label: '物料类型', width: 100, prop: 'materialTypeName', align: 'center' },
        { label: '数量', width: 100, prop: 'quantity', align: 'center' }
      ],
      btnList: [
        //  { name: '详情', type: 'primary', icon: 'edit', click: 'detail', auth: 'wms_stock_detail', ctr: true },
        //  { name: '日志', type: 'primary', icon: 'edit', click: 'log', auth: 'wms_stock_log', ctr: true }
      ],
      queryList: [
        { name: this.global.modelName, type: 'query', prop: 'goodsCode', rowValue: 'modelCode', rowName: 'modelName', placeholder: this.global.modelName, url: url.MODEL_LIST_URL, columns: colunms().modelColumns, pagination: true, queryList: queryField().model },
        { name: '仓库名称', type: 'query', prop: 'warehouseCode', rowValue: 'warehouseCode', rowName: 'warehouseName', placeholder: "仓库名称", url: url.WAREHOUSE_USABLE_URL, columns: colunms().warehouseColumns },
      ]
    }
  },
  created () {
  },
  computed: {
    ...mapGetters([
      'permissions'
    ])
  },
  methods: {
    doDetail (row) {
      // const row = this.$refs['mainGrid'].getSelectOne()
      if (row) {
        this.$router.push({ path: '/wms/stock/detail', query: { warehouseCode: row.warehouseCode, goodsCode: row.goodsCode } })
      }
    },
    doLog (row) {
      // const row = this.$refs['mainGrid'].getSelectOne()
      if (row) {
        this.$router.push({ path: '/wms/stock/log', query: { warehouseCode: row.warehouseCode, goodsCode: row.goodsCode } })
      }
    },
    doQuery (text) {
      this.$refs['mainGrid'].doQuery(text)
    },
    rowCilck (row) {
      this.disabled = row.length == 0
    },
    cancel () {
      this.opShow = false
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
